package com.cj.allTest.genericity;

import java.util.List;

public class demo05 {
    public static void main(String[] args) {
        ArrayList<dog> list = new ArrayList<>(50);
        list.add(new dog());
        list.add(new smallDog());
        //这里会报错add(dog) in ArrayList cannot be applied:to (animal)，意思是无法在狗这个类中找到animal
//        list.add(new animal());
    }
}
class animal{
    public String toString(){
        return "动物";
    }
}
class dog extends animal{
    @Override
    public String toString() {
        return "狗";
    }
}

class smallDog extends dog{
    @Override
    public String toString() {
        return "小狗狗";
    }
}
class ArrayList<E extends dog>{
    private Object[] elementDate;
    private int size = 0;
    //initialCapacity初始容量
    public ArrayList(int initialCapacity){
        this.elementDate = new Object[initialCapacity];
    }

    public boolean add(E e){
        elementDate[size++] = e;
        return true;
    }

    public E get(int index){
        return (E) elementDate[index];
    }
}
